import { LinkProps, TableColumnCtx } from "element-plus"
import { RouteMeta, RouteRecordRaw } from "vue-router"
import { Ref, VNode, h } from "vue"
import { UiDataView } from "."

export interface ExtendedRouteMeta extends RouteMeta {
  key?: string,
  title?: string,
  subTitle?: string,
  fullTitle?: string,
  icon?: string,
  activeIcon?: string,
  notMenu?: boolean,
  notSubMenu?: boolean
}

export type ExtendedRouteRecordRaw = RouteRecordRaw & {
  meta?: ExtendedRouteMeta
}

export type TableCellBtn = LinkProps & { label?: string, onClick?: (e: PointerEvent) => void }

export interface TableColumnConfig<T> extends TableColumnCtx<T> {
  render: (fn?: typeof h, options?: { row?: T, column?: TableColumnCtx<T>, index?: number }) => VNode
}

export type PageParams = {
  pageNum?: number,
  pageSize?: number
}

export type KeyValues = { [k: string]: any }

export type PageListReturnResult = Promise<{ rows: any[], total: number }>

export type PageFetchAction = (params: KeyValues & PageParams) => PageListReturnResult

export type DataViewRef = Ref<InstanceType<typeof UiDataView>>

export enum HttpMethod {
  TRACE = 'TRACE',
  CONNECT = 'CONNECT',
  HEAD = 'HEAD',
  OPTIONS = 'OPTIONS',
  DELETE = 'DELETE',
  PUT = 'PUT',
  POST = 'POST',
  GET = 'GET'
}

export enum Required { NO = 0, YES = 1 }

export enum ContentType {
  JSON = 'application/json',
  FORM = 'application/x-www-form-urlencoded'
}

export type ServiceUrlNode = {
  host?: string,
  port?: any,
  weight?: any,
  _k?: number
}

export type ServiceUrl = {
  originalPath?: string,
  protocol?: string,
  apiServer?: ServiceUrlNode[]
}

export type RequestParamConfig = {
  param?: string,
  paramType?: any,
  paramRule?: string,
  isRequired?: Required,
  defaultValue?: any,
  example?: string,
  desc?: string,
  _k?: number,
  id?: string,
  childrenApiParams?: RequestParamConfig[]
}

export type ServiceParamConfig = KeyValues & RequestParamConfig & {
  source?: string
}

export type ApiConfigForm = KeyValues & {
  apiId?: string,
  versionId?: string,
  name?: string,
  method?: any,
  authenrization?: any,
  requestType?: any,

  requestHeader?: RequestParamConfig[],
  requestBody?: RequestParamConfig[],
  requestPath?: RequestParamConfig[],
  requestParam?: RequestParamConfig[],

  serviceParamserviceHeader?: ServiceParamConfig[],
  serviceBody?: ServiceParamConfig[],
  servicePath?: ServiceParamConfig[],
  serviceParam?: ServiceParamConfig[],

  originalPath?: string,
  protocol?: string,
  apiServer?: ServiceUrl[]
}
